package xna.android;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.Rect;
import android.util.Log;
import android.view.MotionEvent;
import br.com.R;

public class GameController
{
		private Point MasterCenter;
		private Point TouchCenter;
		
		private Sprite masterSprite;
		private Sprite touchSprite;
		
		Context content;
		
		private int sw = 320;
		private int sh = 480;
		
		public Sprite getMasterSprite() {
			return masterSprite;
		}
		
		public Sprite getTouchSprite() {
			return touchSprite;
		}
		
		public GameController(Context content)
		{
			MasterCenter = new Point(55, sh-55);
			TouchCenter = new Point(MasterCenter.x, MasterCenter.y);
			
			masterSprite = new Sprite(BitmapFactory.decodeResource(content.getResources(),
					R.drawable.android), MasterCenter.x, MasterCenter.y);
			touchSprite = new Sprite(BitmapFactory.decodeResource(content.getResources(),
					R.drawable.android), TouchCenter.x, TouchCenter.y);			
		}
		
		public void draw(Canvas spriteBatch)
		{
			touchSprite.setX(TouchCenter.x);
			touchSprite.setY(TouchCenter.y);
			
			masterSprite.draw(spriteBatch);
			touchSprite.draw(spriteBatch);
		}
		
		public int move(MotionEvent event)
		{
			//TouchCenter.x = (int) event.getX();
			//TouchCenter.y = (int) event.getY();
			
			int X = (int) event.getX();
			int Y = (int) event.getY();
			
			//Rect up = new Rect(MasterCenter.x, MasterCenter.y, 50, 20 );
			
			Rect up = new Rect(0, 0, 300, 300 );
			
			Log.d("R", up.toString());
			Log.d("X", ""+X);
			Log.d("Y", ""+Y);
			
			//if (TouchCenter.y < MasterCenter.y)
			if ((Y < MasterCenter.y))//&&(Y > MasterCenter.y-50))
			//if(up.intersect(X, Y, X+1, Y+1))
			//if(up.contains(X, Y))
			{
				Log.d("o","i");
				TouchCenter.y = MasterCenter.y - 10;
				return 1; //up				
			}
			Log.d("R", up.toString());
//			else if (TouchCenter.y > MasterCenter.y)
//			{
//				return 2;
//			}
//			else if (TouchCenter.x < MasterCenter.x)
//			{
//				return 3; //left
//			}
//			else if (TouchCenter.x > MasterCenter.x)
//			{
//				return 4; //right
//			}
			return 0;
		}
		
		public void update()
		{
			touchSprite.update(sw, sh);
		}
}
